<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Accessors (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Accessors (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Accessors (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="RTL.html" rel="up" title="RTL">
<link href="Special-Accessors.html" rel="next" title="Special Accessors">
<link href="RTL-Classes.html" rel="prev" title="RTL Classes">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Accessors">
<div class="nav-panel">
<p>
Next: <a href="Special-Accessors.html" accesskey="n" rel="next">Access to Special Operands</a>, Previous: <a href="RTL-Classes.html" accesskey="p" rel="prev">RTL Classes and Formats</a>, Up: <a href="RTL.html" accesskey="u" rel="up">RTL Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Access-to-Operands"><span>14.3 Access to Operands<a class="copiable-link" href="#Access-to-Operands"> &para;</a></span></h3>
<a class="index-entry-id" id="index-accessors"></a>
<a class="index-entry-id" id="index-access-to-operands"></a>
<a class="index-entry-id" id="index-operand-access"></a>

<a class="index-entry-id" id="index-XEXP"></a>
<a class="index-entry-id" id="index-XINT"></a>
<a class="index-entry-id" id="index-XWINT"></a>
<a class="index-entry-id" id="index-XSTR"></a>
<p>Operands of expressions are accessed using the macros <code class="code">XEXP</code>,
<code class="code">XINT</code>, <code class="code">XWINT</code> and <code class="code">XSTR</code>.  Each of these macros takes
two arguments: an expression-pointer (RTX) and an operand number
(counting from zero).  Thus,
</p>
<div class="example smallexample">
<pre class="example-preformatted">XEXP (<var class="var">x</var>, 2)
</pre></div>

<p>accesses operand 2 of expression <var class="var">x</var>, as an expression.
</p>
<div class="example smallexample">
<pre class="example-preformatted">XINT (<var class="var">x</var>, 2)
</pre></div>

<p>accesses the same operand as an integer.  <code class="code">XSTR</code>, used in the same
fashion, would access it as a string.
</p>
<p>Any operand can be accessed as an integer, as an expression or as a string.
You must choose the correct method of access for the kind of value actually
stored in the operand.  You would do this based on the expression code of
the containing expression.  That is also how you would know how many
operands there are.
</p>
<p>For example, if <var class="var">x</var> is an <code class="code">int_list</code> expression, you know that it has
two operands which can be correctly accessed as <code class="code">XINT (<var class="var">x</var>, 0)</code>
and <code class="code">XEXP (<var class="var">x</var>, 1)</code>.  Incorrect accesses like
<code class="code">XEXP (<var class="var">x</var>, 0)</code> and <code class="code">XINT (<var class="var">x</var>, 1)</code> would compile,
but would trigger an internal compiler error when rtl checking is enabled.
Nothing stops you from writing <code class="code">XEXP (<var class="var">x</var>, 28)</code> either, but
this will access memory past the end of the expression with
unpredictable results.
</p>
<p>Access to operands which are vectors is more complicated.  You can use the
macro <code class="code">XVEC</code> to get the vector-pointer itself, or the macros
<code class="code">XVECEXP</code> and <code class="code">XVECLEN</code> to access the elements and length of a
vector.
</p>
<dl class="table">
<dt><a id="index-XVEC"></a><span><code class="code">XVEC (<var class="var">exp</var>, <var class="var">idx</var>)</code><a class="copiable-link" href="#index-XVEC"> &para;</a></span></dt>
<dd><p>Access the vector-pointer which is operand number <var class="var">idx</var> in <var class="var">exp</var>.
</p>
</dd>
<dt><a id="index-XVECLEN"></a><span><code class="code">XVECLEN (<var class="var">exp</var>, <var class="var">idx</var>)</code><a class="copiable-link" href="#index-XVECLEN"> &para;</a></span></dt>
<dd><p>Access the length (number of elements) in the vector which is
in operand number <var class="var">idx</var> in <var class="var">exp</var>.  This value is an <code class="code">int</code>.
</p>
</dd>
<dt><a id="index-XVECEXP"></a><span><code class="code">XVECEXP (<var class="var">exp</var>, <var class="var">idx</var>, <var class="var">eltnum</var>)</code><a class="copiable-link" href="#index-XVECEXP"> &para;</a></span></dt>
<dd><p>Access element number <var class="var">eltnum</var> in the vector which is
in operand number <var class="var">idx</var> in <var class="var">exp</var>.  This value is an RTX.
</p>
<p>It is up to you to make sure that <var class="var">eltnum</var> is not negative
and is less than <code class="code">XVECLEN (<var class="var">exp</var>, <var class="var">idx</var>)</code>.
</p></dd>
</dl>

<p>All the macros defined in this section expand into lvalues and therefore
can be used to assign the operands, lengths and vector elements as well as
to access them.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Special-Accessors.html">Access to Special Operands</a>, Previous: <a href="RTL-Classes.html">RTL Classes and Formats</a>, Up: <a href="RTL.html">RTL Representation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
